<?php
defined('_JEXEC') or die;
// disable core styles to avoid bs conflict 
OC_Util::$core_styles = array();

if(isDevMode()) {
   OCP\Util::addStyle('resumes', 'resumes');
   OCP\Util::addStyle('resumes', 'share');
   OCP\Util::addStyle('calendar', 'calendar.common');
   OCP\Util::addStyle('company', 'company');

   OCP\Util::addScript('resumes', 'offsitesearch');
   OCP\Util::addScript('resumes', 'share');
   OCP\Util::addScript('resumes', 'resumes');
   OCP\Util::addScript('resumes', 'resumelist');
   OCP\Util::addScript('resumes', 'foldermanage');
   OCP\Util::addScript('resumes', 'resumeactions');
   OCP\Util::addScript('resumes', 'keyboardshortcuts');
} else {
   OCP\Util::addStyle('static', 'resumes');
   OCP\Util::addScript('static', 'apps/resumes.min');
   OCP\Util::addScript('static', 'apps/offsitesearch.min');
}

$lang = PFactory::getLanguage();
$lang->load("com_jobs", JPATH_SITE, "zh-CN");

$terms = isset($_['terms']) ? $_['terms'] : array();
$chosen_site = isset($_['chosen_site']) ? $_['chosen_site'] : array();
$sources = isset($terms['source']) ? $terms['source'] : array();
$last_sync_result = isset($_['last_sync_result']) ? $_['last_sync_result'] : array();
if (in_array($_['tab'], $sources)) {
   $default_source = $_['tab'];
} else {
   $default_source = isset($sources[0]) ? $sources[0] : '';
}
// Internal search
$resumes = isset($_['resumes']) ? $_['resumes'] : array();
$internallist = isset($_['internallist']) ? $_['internallist'] : "";

?>
<script type="text/javascript" src="<?php print_unescaped(OC_Helper::linkTo('resumes/js', 'resumes.php'));?>"></script>

<div class="highsearch_wrap medium offsite_highsearch_wrap" style="top:auto; margin-top:0px;">
   <form action="<?php echo OC_Helper::linkToRoute('resumes_setsearchterm'); ?>" id="offsite_search_form" name="offsite_search_form" method="POST" autocomplete="off">
      <input type="hidden" name="term_id" value="<?php echo isset($_['term_id']) ? $_['term_id'] : 0;?>">
      <div class="highsearch_eachbox clearfix" style="margin:3px 0;">
         <label class="pull-left key" style="width:105px;">搜索网站：</label>
         <ul class="selectsite_ul">
            <?php
            if (!empty($terms) && !isset($terms['is_fill'])) {
               $checked_pipapai = isset($terms['pipapai']) ? "checked" : "";
               $checked_51job = isset($terms['51job']) ? "checked" : "";
               $checked_zhilian = isset($terms['zhilian']) ? "checked" : "";
               $checked_jiancai = isset($terms['jiancai']) ? "checked" : "";
            } elseif (!empty($terms) && isset($terms['is_fill']) && $terms['is_fill'] && !empty($chosen_site)) {
               $checked_pipapai = in_array('pipapai', $chosen_site) ? "checked" : "";
               $checked_51job = in_array('51job', $chosen_site) ? "checked" : "";
               $checked_zhilian = in_array('zhilian', $chosen_site) ? "checked" : "";
               $checked_jiancai = in_array('jiancai', $chosen_site) ? "checked" : "";
            } else {
               $checked_pipapai = "";
               $checked_51job = in_array('51job', $_['accounts']) ? "checked" : "";
               $checked_zhilian = in_array('zhilian', $_['accounts']) ? "checked" : "";
               $checked_jiancai = in_array('jiancai', $_['accounts']) ? "checked" : "";
            }
            ?>
            <li><input type="checkbox" name="source[]" value="pipapai" title="在本站的公司云人才库中搜索" <?=$checked_pipapai?>><a title="在本站的公司云人才库中搜索">公司云人才库</a></li>
            <li><input type="checkbox" name="source[]" value="51job" <?=$checked_51job?>>前程无忧</li>
            <li><input type="checkbox" name="source[]" value="zhilian" <?=$checked_zhilian?>>智联招聘</li>
            <li><input type="checkbox" name="source[]" value="jiancai" <?=$checked_jiancai?>>建筑英才</li>
            <label style="display:none;" for="source[]" class="error">该项必填</label>
         </ul>
      </div>
      <div class="highsearch_eachbox clearfix" style="margin:3px 0;">
         <label class="pull-left key" style="width:105px; padding-top:5px;">根据职位条件搜：</label>
         <div class="selectsite_div clearfix">
            <input type="text" class="input-xlarge" name="job_name" id="job_name" readonly style="cursor:pointer; padding:2px 6px;" value="<?php echo isset($terms['job_name']) ? $terms['job_name'] : "";?>" />
            <input type="hidden" name="job_id" id="job_id" value="<?php echo isset($terms['job_id']) ? $terms['job_id'] : "";?>"/>
            <a href="javascript:;" class="ppp_whitebtn" id="selectjobposition" style="padding:2px 6px;">选择职位</a>
            <em>根据职位快捷搜索，匹配条件将默认作为搜索条件</em>
            <a href="javascript:;" class="searchmore_btn medium"><i class="up"></i></a>
         </div>
      </div>

      <div class="detail_srhwrapper">
         <div class="detail_srhform">
            <div class="form-horizontal clearfix">
               <div id="searchterms">
                  <?php echo $_['searchterms']; ?>
               </div>
               <div class="control-group pull-left" style="width:100%;">
                  <label for="" class="control-label key"></label>
                  <div class="controls">
                     <input type="submit" class="ppp_bluebtn srh_subbtn" disabled value="搜 索">
                     <a href="javascript:;" id="clear_form" class="medium">清除条件</a>
                     <span style="display:none;" class="error systeminfo"></span>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </form>
</div>

<div id="offsitesearch_result" class="offsitesearch_result" style="<?php echo empty($sources) ? "display:none;" : "";?>">
   <div class="hr_inner_navigate hr_navigate_static clearfix">
      <ul id="search_tabs">
         <?php if (isset($terms['pipapai'])): ?>
         <li class="<?php echo $default_source=='pipapai' ? 'cur_li' : '';?>" data-source="pipapai">
            <a href="javascript:;">公司云人才库 <i class="downok"></i></a>
         </li>
         <?php endif;?>
         <?php if (isset($terms['51job'])): ?>
         <li class="<?php echo $default_source=='51job' ? 'cur_li' : '';?>" data-source="51job">
            <a href="javascript:;" class="51job" title="<?php echo (isset($last_sync_result['51job']['result']) && $last_sync_result['51job']['result']=='success') ? "搜索完成" : "搜索中";?>">前程无忧 <i class="<?php echo (isset($last_sync_result['51job']['result']) && $last_sync_result['51job']['result']=='success') ? "downok" : "loading";?>"></i></a>
         </li>
         <?php endif;?>
         <?php if (isset($terms['zhilian'])): ?>
         <li class="<?php echo $default_source=='zhilian' ? 'cur_li' : '';?>" data-source="zhilian">
            <a href="javascript:;" class="zhilian" title="<?php echo (isset($last_sync_result['zhilian']['result']) && $last_sync_result['zhilian']['result']=='success') ? "搜索完成" : "搜索中";?>">智联招聘 <i class="<?php echo (isset($last_sync_result['zhilian']['result']) && $last_sync_result['zhilian']['result']=='success') ? "downok" : "loading";?>"></i></a>
         </li>
         <?php endif;?>
         <?php if (isset($terms['jiancai'])): ?>
         <li class="<?php echo $default_source=='jiancai' ? 'cur_li' : '';?>" data-source="jiancai">
            <a href="javascript:;" class="jiancai" title="<?php echo (isset($last_sync_result['jiancai']['result']) && $last_sync_result['jiancai']['result']=='success') ? "搜索完成" : "搜索中";?>">建筑英才 <i class="<?php echo (isset($last_sync_result['jiancai']['result']) && $last_sync_result['jiancai']['result']=='success') ? "downok" : "loading";?>"></i></a>
         </li>
         <?php endif;?>
      </ul>
      <div class="resume_search pull-left">
         <div class="chooseresumeshow medium pull-left" style="margin-left:20px;">
            <span>显示：</span>
            <a class="showways_close <?php echo (!isset($_['showsearchresumedetails']) || empty($_['showsearchresumedetails'])) ? 'curselect' : ''; ?>" data-placement="left" href="javascript:;" title="列表显示"></a>
            <a class="showways_open  <?php echo (isset($_['showsearchresumedetails']) && $_['showsearchresumedetails'] == 1) ? 'curselect' : ''; ?>" data-placement="right" href="javascript:;" title="详情显示"></a>
         </div>
      </div>
   </div>
   
   <div class="osearch_resumeswrap" style="width:100%; padding-right:0px; max-width:100%;">
      <div class="hr_resume_tablebox" style="padding-bottom:0px; margin-top:0px;">

         <table class="resume_listtable medium pipapai openit" data-source="pipapai" width="100%" border="0" cellpadding="0" cellspacing="0" style="<?php echo $default_source=='pipapai' ? "" : "display:none;";?>border-collapse:separate;">
            <thead>
               <tr>
                  <th align="left" id='headerName' style="padding-left:10px;">
                     <input type="checkbox" id="select_all" autocomplete="off" style="margin-right:0px;"/>
                     <em style="margin-right:20px; font-weight:normal;">全选</em>
                     <span class='name'>姓名 / 信息</span>
                     <span class="actions_change">
                     <?php if($_['allowZipDownload']) : ?>
                        <span class='selectedActions'>
                           <a href="" class="download">
                              <i class="download"></i>
                              <?php echo $l->t('Download')?>
                           </a>
                        </span>
                     <?php endif; ?>

                     <span class="selectedActions">
                        <a href="" class="save">
                           <i class="save"></i>
                           <?php echo $l->t('Save')?>
                        </a>
                     </span>
                     <span class="selectedActions">
                        <a href="" class="unsave">
                           <i class="unsave"></i>
                           <?php echo $l->t('Unsave')?>
                        </a>
                     </span>

                     <?php if ($_['permissions'] & OCP\PERMISSION_DELETE): ?>
                        <span class="selectedActions">
                           <a href="" class="delete">
                              <i class="delete"></i>
                              <?php echo $l->t('Delete')?>
                           </a>
                        </span>
                        <span class="selectedActions">
                           <a href="" class="invite">
                              <i class="invite"></i>
                                                                               邀请评测
                           </a>
                        </span>

                     <?php endif; ?>
                     </span>
                  </th>
                  <th align="left" id="headerResumeStatus">
                     <span>状态<i class="down_triangle"></i>
                        <?php PResumesHelper::showResumeStatuses($_['resumeStatuses'],0,1); ?>
                     </span>
                  </th>
                  <th align="left" id="headerWork"><span><a class='sort <?=($_['topnlist'] ? 'topnlist': '')?>' data-orderby='workexp' data-orderdir='desc' href="javascript:;">工作经验<i class="downblack"></i></a></span></th>
                  <th align="left" id="headerDegree"><span><a class='sort <?=($_['topnlist'] ? 'topnlist': '')?>' data-orderby='degree' data-orderdir='desc' href="javascript:;">学历<i class="downblack"></i></a></span></th>
                  <th align="left" id="headerPosition" style="display: <?=(empty($jobid) ? '' : 'none')?>"><span>申请职位</span></th> 
                  <!--<th align="left" id="headerSchool"><span>毕业院校-专业</span></th>-->
                  
                  <th align="center" id="headerMatch"><span><a class='sort <?=($_['topnlist'] ? 'topnlist': '')?>' data-orderby='matchresult' data-orderdir='desc' href="javascript:;">匹配度<i class="downblack"></i></a></span></th>
                  <th align="center" id="headerTest"><span>应聘进度</span></th>
                  <th align="center" id="headerDate"><span><a class='sort <?=($_['topnlist'] ? 'topnlist': '')?>' data-orderby='added' data-orderdir='desc' href="javascript:;">申请时间<i class="downblack"></i></a></span></th>
               </tr>
            </thead>
            <tbody id="resumeList">
               <?php
               // Show tips when searching
               if (empty($resumes)) {
                  echo '<tr><td colspan=8>没有找到符合条件的简历</td></tr>';
               } else {
                  echo $internallist;
               }
               ?>
            </tbody>
            <?php if(!empty($_['pagination']) && $_['pagination']->pagesTotal > 1):?>
            <tfoot>
               <tr><td colspan="8">
                     <?php echo $_['pagination']->getListFooter();?>
               </td></tr>
            </tfoot>
            <?php endif;?>
         </table>
         <?php echo empty($_['offsitelist']) ? '' : $_['offsitelist'];?>
      </div>
   </div>
</div>


<!-- Modal 51job -->
<div id="accountsetdialog_51job" class="modal hide accountsetdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<!-- Modal zhilian -->
<div id="accountsetdialog_zhilian" class="modal hide accountsetdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>

<?php if(!empty($_['syncto'])): ?>
<div id="popup_syncto" data-syncto='<?=json_encode($_['syncto'])?>'></div>
<div id="sync_now"></div>
<?php endif;?>
<div id="syncinfo" data-termid="<?php echo isset($_['term_id']) ? $_['term_id'] : 0;?>">
   <?php
   $syncing = 0;
   foreach ($last_sync_result as $source => $v) {
      $result = isset($v['result']) ? $v['result'] : '';
      if ($result != 'success') {
         $syncing++;
      }
      $totalrecords = isset($v['totalrecords']) ? $v['totalrecords'] : 0;
      $totalpages = isset($v['totalpages']) ? $v['totalpages'] : 0;
      $nowpage = isset($v['nowpage']) ? $v['nowpage'] : 0;
      echo '<div id="'.$source.'" data-result="'.$result.'" data-totalrecords="'.$totalrecords.'" data-totalpages="'.$totalpages.'" data-nowpage="'.$nowpage.'" ></div>';
   }
   // when last_sync_result is not ready, we check if sources are valid list 
   if(!$syncing) {
     foreach($sources as $s) {
        if($s != 'pipapai')
          $syncing++;
     }
   }

   $syncing = json_encode($syncing);
   ?>
   <div id="syncing" data-syncing='<?=$syncing?>'></div>
</div>

<div id="resumesearch_wrap" style="display: none;"></div>
<div id="persontest_result" class="modal fade hide"></div>
<input type="hidden" name="allowZipDownload" id="allowZipDownload" value="<?php echo $_['allowZipDownload']; ?>" />
<input type="hidden" id="orderBy" value="<?php echo $_['orderBy']; ?>" />
<input type="hidden" id="orderDir" value="<?php echo $_['orderDir']; ?>" />
<input type="hidden" name="searchtoken" id="searchtoken" value="<?php echo !empty($_['searchtoken']) ? $_['searchtoken'] : ''; ?>" />
